import {
  getMessageNumber
} from '@/service/sys';
import cache from './cache';
const setBedge = function () {


  if (!cache.get('token')) {
    plus.runtime.setBadgeNumber(-1)
    plus.runtime.setBadgeNumber(0)
    return
  }
  getMessageNumber().then((res) => {
    if (res.code == 0) {
      if (res.data > 0) {
        plus.runtime.setBadgeNumber(res.data)
        uni.setTabBarBadge({
          index: 1,
          text: res.data + ''
        })
        console.log(res.data)
      } else {
        uni.removeTabBarBadge({
          index: 1,
        })
        console.log(res.data, "00000")
        plus.runtime.setBadgeNumber(-1)
        plus.runtime.setBadgeNumber(0)
      }
    }
  }).catch((err) => {
    console.log(err, 11);
  })
};

export default setBedge;
